﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace GataBaseSys
{
    public partial class WebForm2 : System.Web.UI.Page
    {
       
        //声明集合
        public static List<Auction> list = null;
        //定义每页的数据数
        public static int size = 12;
        //定义尾页页数
        public static int lastPage = 0;
        GataBaseBLL bll = new GataBaseBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            //声明index
            int index = Convert.ToInt32(Request["index"]);
            list = bll.GetListALL();
            lastPage = list.Count / size;
            this.Repeater1.DataSource = list.Skip((index - 1) * size).Take(size).ToList();
            this.Repeater1.DataBind();
        }
        public static string GetValue(string val)
        {
            if (val == "1")
            {
                return "<b>北京</b>";
            }
            else if (val == "2")
            {
                return "<b>上海</b>";
            }
            else if (val == "3")
            {
                return "<b>重庆</b>";
            }
            else if (val == "4")
            {
                return "<b>广州</b>";
            }
            else if (val == "5")
            {
                return "<b>深圳</b>";
            }
            else
            {
                return "<b>贵州</b>";
            }
        }
        //按名称进行模糊查询
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string Name = this.txtName.Text;
            this.Repeater1.DataSource = bll.GetListByName(Name);
            this.Repeater1.DataBind();
        }

        //写字楼
        protected void btnOffice_Click(object sender, EventArgs e)
        {
            int name = 1;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //不限
        protected void btnUnLimit_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL();
            this.Repeater1.DataBind();
        }
        //公寓
        protected void btnApartment_Click(object sender, EventArgs e)
        {
            int name = 2;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //住宅
        protected void btnResidence_Click(object sender, EventArgs e)
        {
            int name = 3;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //商业
        protected void btnBusiness_Click(object sender, EventArgs e)
        {
            int name = 4;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //别墅
        protected void btnVilla_Click(object sender, EventArgs e)
        {
            int name = 5;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //自由购
        protected void btnFreeShop_Click(object sender, EventArgs e)
        {
            int name = 6;
            this.Repeater1.DataSource = bll.GetListByID(name);
            this.Repeater1.DataBind();
        }
        //不限（地址查询）
        protected void btnLimit_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL();
            this.Repeater1.DataBind();
        }
        //北京
        protected void btnBeiJing_Click(object sender, EventArgs e)
        {
            int address = 1;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //上海
        protected void btnShangHai_Click(object sender, EventArgs e)
        {
            int address = 2;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //重庆
        protected void btnChongQing_Click(object sender, EventArgs e)
        {
            int address = 3;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //广州
        protected void btnGuangZhou_Click(object sender, EventArgs e)
        {
            int address = 4;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //深圳
        protected void BtnShenZhen_Click(object sender, EventArgs e)
        {
            int address = 5;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //贵州
        protected void btnGuiZhou_Click(object sender, EventArgs e)
        {
            int address = 6;
            this.Repeater1.DataSource = bll.getListByAddress(address);
            this.Repeater1.DataBind();
        }
        //最新发布（日期降序排序）
        protected void btnNew_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL().OrderByDescending(a => a.AuctionUpload);
            this.Repeater1.DataBind();
        }
        //默认排序
        protected void btnNonmal_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL();
            this.Repeater1.DataBind();
        }
        //精品房屋（价格降序）
        protected void btnCount_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL().OrderByDescending(a => a.AuctionPrice);
            this.Repeater1.DataBind();
        }
        //廉价实惠（价格升序）
        protected void btnSingle_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL().OrderBy(a => a.AuctionPrice);
            this.Repeater1.DataBind();
        }
        //捡漏房源（日期升序）
        protected void btnLost_Click(object sender, EventArgs e)
        {
            this.Repeater1.DataSource = bll.GetListALL().OrderBy(a => a.AuctionUpload);
            this.Repeater1.DataBind();
        }
        //价格查询
        protected void BtnSelectPrice_Click(object sender, EventArgs e)
        {
            int PreOne = Convert.ToInt32(this.txtPriceOne.Text);
            int PreTwo = Convert.ToInt32(this.txtPriceTwo.Text);
            this.Repeater1.DataSource = bll.GetListByOrder(PreOne, PreTwo);
            this.Repeater1.DataBind();
        }
    }
}